<style lang="less">
  .special-delivery {
    height: 92%;
    display: flex;
    .split_order {
      color: #FF4949;
    }
    .row-info-bg {
      background: #FFAEB9;
    }
    .split-order-ageing {
      background-color: #FF6464;
      color: black;
    }
    .el-form-item {
      margin-bottom: 5px;
    }
    .el-select {
      width: 100%;
    }
    .el-cascader {
      width: 100%;
    }
    .el-date-editor {
      width: 100%;
    }
    .left {
      flex: 0 0 400px;
      display: flex;
      flex-direction: column;
      width: 400px;
      .el-form-item {
        margin-bottom: 20px;
      }
      .tj {
        text-align: center;
        border-right: 1px solid #dfe6ec;
        border-top: 1px solid #dfe6ec;
        .bg-purple-light {
          margin: 0;
          font-weight: bold;
        }
        .bg-purple {
          padding: 10px;
        }
        .el-col {
          border-left: 1px solid #dfe6ec;
          border-bottom: 1px solid #dfe6ec;
        }
      }
      .zcdd {
        margin: 5px 0 5px 0;
        border: 1px solid #dfe6ec;
        overflow-y: auto;
        flex: 1;
        display: flex;
        flex-direction: column;
        .panel-header {
          background-color: #87CEFA;
          padding: 10px 5px 10px 10px;
          .title {

          }
          .code {
            float: right;
          }
        }
        .panel-body {
          padding: 10px;
          flex: 1;
          display: flex;
          flex-direction: column;
          .ysxl {
            margin-top: 10px;
            padding: 0 5px 0 5px;
            .el-col {
              background-color: #87CEFA;
              padding-bottom: 5px;
            }
          }
          .el-form {
            padding-bottom: 5px;
          }
          .aaa {
            flex: 1;
            padding: 10px;
            div {
              margin-left: 5px;
              margin-bottom: 5px;
            }
            .fa-remove {
              margin-left: 5px;
              color: red;
              cursor: pointer;
            }
          }
        }
      }

    }
    .center {
      margin-left: 10px;
      margin-bottom: 10px;
      flex: 1;
      overflow-x: auto;
      display: flex;
      flex-direction: column;
      .el-tabs__content{
        flex: 1;
        display: flex;
        flex-direction: column;
        .el-tab-pane{
          flex: 1;
          display: flex;
          flex-direction: column;
          .el-table{
            flex: 1;
            overflow-y: auto;
            .el-table__body-wrapper{
              overflow-y: auto;
            }
          }
        }
      }
    }
  }
  #addVehicleTemporaryDialog{
    .el-dialog{
      .el-dialog__body{
        padding: 20px 0px 10px 0px;
      }
    }
  }
  .special-delivery-top{
    background-color: red;
    margin-bottom: 5px;
    height: 35px;
    text-align: center;
    color: white;
    font-size: 18px;
    font-weight: 700;
    padding-top: 10px;
    .top-img{
      height: 30px;
      width: 30px;
      vertical-align: middle;
      padding-right: 10px;
    }
  }
</style>
<template>
  <section>
    <div id="special-delivery-top" class="special-delivery-top"  v-bind:style="ageingDisplay">
        <img class="top-img" src="../../assets/warning.png"/>您有{{left.goodsVehicleStatistics.ageingWarningNum}}笔订单逾期未发车，请及时处理
    </div>
    <div class="special-delivery">
      <div class="left">
        <div class="tj">
          <el-row>
            <el-col :span="5">
              <div class="bg-purple-light">车辆</div>
            </el-col>
            <el-col :span="5">
              <div class="bg-purple-light">票数</div>
            </el-col>
            <el-col :span="5">
              <div class="bg-purple-light">重量</div>
            </el-col>
            <el-col :span="5">
              <div class="bg-purple-light">体积</div>
            </el-col>
            <el-col :span="4">
              <div class="bg-purple-light">件数</div>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="5">
              <div class="bg-purple">{{left.goodsVehicleStatistics.vehicleNum || 0}}</div>
            </el-col>
            <el-col :span="5">
              <div class="bg-purple">{{left.goodsVehicleStatistics.orderStatistics.orderSum || 0}}</div>
            </el-col>
            <el-col :span="5">
              <div class="bg-purple">{{left.goodsVehicleStatistics.orderStatistics.totalWeight?left.goodsVehicleStatistics.orderStatistics.totalWeight.toFixed(2):0}}</div>
            </el-col>
            <el-col :span="5">
              <div class="bg-purple">{{left.goodsVehicleStatistics.orderStatistics.totalVolume?left.goodsVehicleStatistics.orderStatistics.totalVolume.toFixed(2):0}}</div>
            </el-col>
            <el-col :span="4">
              <div class="bg-purple">{{left.goodsVehicleStatistics.orderStatistics.total || 0}}</div>
            </el-col>
          </el-row>
        </div>
        <div class="zcdd">
          <div class="panel-header">
            <span class="title">装车调度</span>
            <span class="code">{{code}}</span>
          </div>
          <div class="panel-body">
            <el-form :model="left.loadingListRoute" label-position="left" ref="loadingListForm" label-width="90px">
              <el-form-item label="选择车辆"
                            :rules="[{ type:'object', required: true, message: '请选择车辆', trigger: 'change' }]"
                            prop="vehicle">
                <el-select v-model="left.loadingListRoute.vehicle"
                           filterable
                           style="width: 220px"
                           value-key="plateNumber"
                           placeholder="请输入车牌号码"
                           :loading="left.searchVehicleLoading">
                  <el-option
                    v-for="item in left.vehicles"
                    :key="item.plateNumber"
                    :label="item.plateNumber"
                    :value="item">
                  </el-option>
                </el-select>
                <el-button type="primary" icon="el-icon-plus" @click="addVehicle"></el-button>
              </el-form-item>
              <el-form-item
                label="出发站">
                <el-cascader
                  placeholder="请选择配载中心"
                  :options="$store.state.initOrganizations"
                  :props="{label: 'name',value: 'id'}"
                  change-on-select
                  disabled
                  v-model="currentOrganizationIds"
                ></el-cascader>
              </el-form-item>
              <el-form-item
                v-if="!left.endOrganizationInput"
                :rules="[{type: 'array', required: true, message: '请选择配载中心', trigger: 'change' }]"
                prop="endOrganizationId"
                label="目的站">
                <el-cascader
                  placeholder="请选择配载中心"
                  :options="$store.state.initOrganizations"
                  :props="{label: 'name',value: 'id'}"
                  change-on-select
                  v-model="left.loadingListRoute.endOrganizationId"
                ></el-cascader>
              </el-form-item>
              <el-form-item
                v-if="left.endOrganizationInput"
                :rules="[{required: true, message: '请输入目的地', trigger: 'blur' }]"
                prop="endOrganizationName"
                label="目的站">
                <el-input v-model="left.loadingListRoute.endOrganizationName" style="width: 225px" placeholder="请输入目的地"></el-input>
                <el-button @click="left.endOrganizationInput=!left.endOrganizationInput" type="text">选择</el-button>
              </el-form-item>
              <el-form-item label="途径站">
                <el-cascader
                  v-for="(domain, index) in left.loadingListRoute.site" :key="index"
                  placeholder="请选择配载中心"
                  :options="$store.state.initOrganizations"
                  :props="{label: 'name',value: 'id'}"
                  change-on-select
                  v-model="domain.organizationId"
                ></el-cascader>
              </el-form-item>
              <div style="text-align: right">
                <el-button type="primary" @click="addLoadingListRoute">增加</el-button>
              </div>
            </el-form>
            <div class="aaa" style="background-color: lightblue">
              <span>运输线路：</span>
              <div v-if="left.loadingListRoute.startOrganizationId.length">
                起：{{currentLabels(left.loadingListRoute.startOrganizationId)}}
              </div>
              <div v-for="(item,index) in left.loadingListRoute.site" v-if="item.organizationId.length" :key="index">
                经：{{currentLabels(item.organizationId)}}
                <i class="fa fa-remove fa-lg" @click="deleteLoadingListRoute(index,item)"></i>
              </div>
              <div v-if="!left.endOrganizationInput && left.loadingListRoute.endOrganizationId.length">
                终：{{currentLabels(left.loadingListRoute.endOrganizationId)}}
              </div>
              <div v-if="left.endOrganizationInput && left.loadingListRoute.endOrganizationName!=null">
                终：{{ left.loadingListRoute.endOrganizationName }}
              </div>
            </div>
            <div style="text-align: center;margin-top: 10px">
              <el-button type="primary" @click="resetLoadingList">重置</el-button>
              <el-button type="primary" @click="addLoadingList" :disabled="selectedLoadingList!=null && selectedLoadingList.poll>0">保存</el-button>
            </div>
          </div>
        </div>
        <el-table
          ref="singleTable"
          :data="left.loadingList.tableData"
          v-loading="left.loadingList.listLoading"
          highlight-current-row
          @current-change="loadingListHandleCurrentChange"
          border height="250">
          <el-table-column label="预装车列表">
            <el-table-column
              prop="plateNumber"
              label="车牌号"
              width="100">
            </el-table-column>
            <el-table-column
              show-overflow-tooltip
              prop="driverInfoName"
              label="司机"
              width="80">
            </el-table-column>
            <el-table-column
              show-overflow-tooltip
              prop="number"
              label="装车单号"
              width="100">
            </el-table-column>
            <el-table-column
              show-overflow-tooltip
              prop="poll"
              label="票件重体">
              <template slot-scope="scope">
                {{scope.row.poll}}票{{scope.row.totalAmount}}件{{scope.row.totalWeight.toFixed(2)}}吨{{scope.row.totalVolume.toFixed(2)}}方
              </template>
            </el-table-column>
          </el-table-column>
        </el-table>
        <el-col :span="24" class="toolbar">
          <el-pagination
            :current-page="left.loadingList.currentPage"
            :page-size="left.loadingList.pageSize"
            @size-change="loadingListSizeChange"
            @current-change="loadingListCurrentChange"
            layout="total,sizes,prev, pager, next, jumper"
            :total="left.loadingList.total" style="float: right">
          </el-pagination>
        </el-col>
        <el-dialog title="新增临时车辆" :visible.sync="left.addVehicleDialogVisible"
          size="tiny" id="addVehicleTemporaryDialog">
          <el-form ref="addVehicleForm" :model="left.vehicleForm" label-width="40%">
            <el-form-item label="车牌号"
                          :rules="[
                          { required: true, message: '请输入车牌号', trigger: 'blur' },
                          { max: 10, message: '长度不能大于10个字符', trigger: 'blur' }
                        ]"
                          prop="plateNumber">
              <el-input v-model="left.vehicleForm.plateNumber" style="width: 60%"></el-input>
            </el-form-item>
            <el-form-item label="司机姓名"
                          :rules="[
                          { required: true, message: '请输入司机姓名', trigger: 'blur' },
                          { max: 20, message: '长度不能大于20个字符', trigger: 'blur' }
                        ]"
                          prop="name">
              <el-input v-model="left.vehicleForm.name"  style="width: 60%"></el-input>
            </el-form-item>
            <el-form-item label="联系方式"
                          :rules="[
                          { required: true, message: '请输入联系方式', trigger: 'blur' },
                          { max: 13, message: '长度不能大于13个字符', trigger: 'blur' }
                        ]"
                          prop="phone">
              <el-input v-model="left.vehicleForm.phone"  style="width: 60%"></el-input>
            </el-form-item>
          </el-form>
          <el-row style="border: 1px solid #E9E9E9;height: 140px">
            <div style="width: 80%;margin: 0px auto">
              <el-col span="24">
                <p style="font-weight: 700;color: grey">历史使用车辆</p>
              </el-col>
              <div style="width: 80%">
                <el-col span="8" style="padding-bottom: 10px"  v-for="(item,index) in left.vehicleTableDataTemporary" :key="index">
                  <el-button style="background-color: #E9E9E9;width: 90%" @click="selectVehicleInfoTemporary(item)">{{item.plateNumber}}</el-button>
                </el-col>
              </div>
            </div>
          </el-row>
          <span slot="footer" class="dialog-footer">
          <el-button @click="left.addVehicleDialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="saveVehicle">确 定</el-button>
        </span>
        </el-dialog>
      </div>
      <el-tabs v-model="tabActiveName" class="center" type="border-card">
        <el-tab-pane label="未配载" name="first">
          <ue-search-bar empty-text="no_stowage组查询条件未配置" ref="ueSearchBarNoStowage" v-model="center.noStowage.searchCondition" :data="querysNoStowage" label-width="100px">
          </ue-search-bar>

          <!-- 操作 -->
          <el-col :span="24" style="margin-bottom: 10px">
            <el-col :span="12">
              <el-switch
                v-model="center.noStowage.orderType"

                >
              </el-switch>
              <el-select
                style="width: 200px"
                v-model="center.noStowage.loadingListRouteId"
                placeholder="请选择下货地">
                <el-option
                  v-for="item in center.noStowage.routes"
                  :key="item.id"
                  :label="item.dischargeOrganizationName"
                  :value="item.id">
                </el-option>
              </el-select>
              <el-button type="primary"
                         :disabled="this.center.noStowage.totalPoll===0"
                         @click="addLoadingListTunkTask">移入
              </el-button>
              <el-button type="primary" @click="confirmSplit"
                         :disabled="selectedNoStowageTrunkTask === null
                       || selectedNoStowageTrunkTask.type==='group'
                       || selectedNoStowageTrunkTask.pid !== null
                       || selectedNoStowageTrunkTask.childrenNum !== null">拆分订单</el-button>
              <el-button type="primary" @click="removeSplit"
                         :disabled="selectedNoStowageTrunkTask === null
                       || selectedNoStowageTrunkTask.type==='group'
                       || selectedNoStowageTrunkTask.childrenNum === null
                       || !isCancleSplitTrunkTask">取消拆分</el-button>
              <el-button type="primary"
                         :disabled="selectedLoadingList === null || this.center.noStowage.totalPoll===0"
                         @click="handleDirect">大车直送</el-button>
            </el-col>
            <el-col :span="8">
              当前选中：{{center.noStowage.totalPoll}}票 {{center.noStowage.totalAmount}}件 {{center.noStowage.totalWeight.toFixed(2)}}吨 {{center.noStowage.totalVolume.toFixed(2)}}方
            </el-col>
            <el-col :span="4" style="text-align: right">
              <el-button type="primary" @click="noStowageExport">导出</el-button>
              <el-button type="primary" @click="noStowageQuery">查询</el-button>
              <el-button type="primary" @click="noStowageReset">重置</el-button>
            </el-col>
          </el-col>

          <!--列表-->
          <ue-el-table ref="noStowageTable" :data="center.noStowage.tableData"
                       highlight-current-row border
                       height="100%"
                       current-row-key="id"
                       @select="noStowageSelect"
                       @current-change="handleNoStowageCurrentChange"
                       v-loading="center.noStowage.listLoading"
                       @selection-change="noStowageSelsChange"
                       :row-class-name="tableRowClassName"
                       style="width: 100%;">
            <el-table-column type="selection" fixed="left" width="55">
            </el-table-column>
            <ue-el-table-tree-column fixed
                                     :remote="remoteNoStowage"
                                     prop="label"
                                     label="订单号"
                                     child-num-key="num"
                                     width="230">
            </ue-el-table-tree-column>
            <el-table-column show-overflow-tooltip prop="order.shipmentsDate" label="发运日期" width="120">
            </el-table-column>
            <el-table-column label="等通知放货" width="120" align="center">
              <template slot-scope="scope">
                <span v-if="scope.row.pid===null"> {{scope.row.order.noticeDeliveryStatus === 101022001?'否':(scope.row.order.noticeDeliveryStatus === 101022002? '是':scope.row.order.noticeDeliveryStatusName)}}</span>
              </template>
            </el-table-column>
            <el-table-column show-overflow-tooltip prop="order.cargoNames" label="货物品名" width="120">
            </el-table-column>
            <el-table-column show-overflow-tooltip prop="order.orderStatusName" label="订单状态" width="120">
            </el-table-column>
            <el-table-column prop="order.packTypeNames" label="包装" width="120">
            </el-table-column>
            <el-table-column prop="order.sendContactName" label="收货人名称" width="160">
            </el-table-column>
            <el-table-column prop="order.sendContactPhone" label="收货人手机" width="160">
            </el-table-column>
            <el-table-column prop="order.sendStreet" label="收货人地址" width="160">
            </el-table-column>
            <el-table-column prop="order.transportationNumber" label="运单号" width="160">
            </el-table-column>
            <el-table-column prop="order.extractTypeName" label="提货状态" width="120">
            </el-table-column>
            <el-table-column label="预计入库" width="120">
            </el-table-column>
            <el-table-column label="入库状态" width="120">
              <template slot-scope="scope">
                <span v-if="scope.row.whetherStorage">已入库</span>
                <span v-else>未入库</span>
              </template>
            </el-table-column>
            <el-table-column prop="order.sendTypeName" label="配送方式" width="120">
            </el-table-column>
            <el-table-column show-overflow-tooltip prop="order.sendTime" label="要求到达时间" width="140">
            </el-table-column>
            <el-table-column prop="order.agingName" label="运输方式" width="120">
            </el-table-column>
            <el-table-column prop="order.orderPrice" label="运费(元)" width="90">
              <template slot-scope="scope">
                <span v-if="scope.row.pid===null">{{scope.row.order.orderPrice}}</span>
              </template>
            </el-table-column>
            <el-table-column prop="order.paymentTypeName" label="结算方式" width="100">
            </el-table-column>
            <el-table-column prop="order.shipmentsContactName" label="发货人名称" width="160">
            </el-table-column>
            <el-table-column prop="order.remark" label="备注" width="120">
            </el-table-column>
            <el-table-column fixed="right" prop="order" label="件重体" width="140" :formatter="formatterOrderCargos">
            </el-table-column>
          </ue-el-table>
          <split-task ref="mySplitTask" :task="selectedNoStowageTrunkTask" @confirmSplit="confirmSplitHandle"></split-task>
        </el-tab-pane>
        <el-tab-pane label="已配载" name="second">
          <ue-search-bar empty-text="have_stowage组查询条件未配置" ref="ueSearchBarHaveStowage" v-model="center.haveStowage.searchCondition" :data="querysHaveStowage" label-width="100px">
          </ue-search-bar>

          <!-- 操作 -->
          <el-col :span="24" style="margin-bottom: 10px">
            <el-col :span="12">
              <el-switch
                :disabled="!this.center.haveStowage.loadingListId"
                v-model="center.haveStowage.orderType"

                >
              </el-switch>
              <el-select
                style="width: 200px"
                clearable
                @change="haveStowageLoadingListRouteChange"
                v-model="center.haveStowage.loadingListRouteId"
                placeholder="请选择下货地">
                <el-option
                  v-for="item in center.haveStowage.routes"
                  :key="item.id"
                  :label="item.dischargeOrganizationName"
                  :value="item.id">
                </el-option>
              </el-select>
              <el-button type="primary"
                         :disabled="this.center.haveStowage.totalPoll===0"
                         @click="removeLoadingListTunkTask">移出
              </el-button>
            </el-col>
            <el-col :span="8">
              当前选中：{{center.haveStowage.totalPoll}}票 {{center.haveStowage.totalAmount}}件 {{center.haveStowage.totalWeight}}吨 {{center.haveStowage.totalVolume}}方
            </el-col>
            <el-col :span="4" style="text-align: right">
              <el-button type="primary">导出</el-button>
              <el-button type="primary" :disabled="!this.center.haveStowage.loadingListId" @click="haveStowageQuery">查询
              </el-button>
              <el-button type="primary" @click="haveStowageReset">重置</el-button>
            </el-col>
          </el-col>

          <!--列表-->
          <ue-el-table ref="haveStowageTable" :data="center.haveStowage.tableData"
                       highlight-current-row border
                       height="100%"
                       v-loading="center.haveStowage.listLoading"
                       @select="haveStowageSelect"
                       @selection-change="haveStowageSelsChange"
                       :row-class-name="tableRowClassName"
                       style="width: 100%;">
            <el-table-column type="selection" fixed="left" width="55">
            </el-table-column>
            <ue-el-table-tree-column fixed
                                     :remote="remoteHaveStowage"
                                     prop="label"
                                     label="订单号"
                                     child-num-key="num"
                                     width="230">
            </ue-el-table-tree-column>
            <el-table-column show-overflow-tooltip prop="order.shipmentsDate" label="发运日期" width="120">
            </el-table-column>
            <el-table-column label="等通知放货" width="120" align="center">
              <template slot-scope="scope">
                <span v-if="scope.row.pid===null"> {{scope.row.order.noticeDeliveryStatus === 101022001?'否':(scope.row.order.noticeDeliveryStatus === 101022002? '是':scope.row.order.noticeDeliveryStatusName)}}</span>
              </template>
            </el-table-column>
            <el-table-column show-overflow-tooltip prop="order.cargoNames" label="货物品名" width="120">
            </el-table-column>
            <el-table-column prop="order.packTypeNames" label="包装" width="120">
            </el-table-column>
            <el-table-column prop="order.sendContactName" label="收货人名称" width="160">
            </el-table-column>
            <el-table-column prop="order.sendContactPhone" label="收货人手机" width="160">
            </el-table-column>
            <el-table-column prop="order.sendStreet" label="收货人地址" width="160">
            </el-table-column>
            <el-table-column prop="order.transportationNumber" label="运单号" width="160">
            </el-table-column>
            <el-table-column prop="order.extractTypeName" label="提货状态" width="120">
            </el-table-column>
            <el-table-column label="预计入库" width="120">
            </el-table-column>
            <el-table-column label="入库状态" width="120">
              <template slot-scope="scope">
                <span v-if="scope.row.whetherStorage">已入库</span>
                <span v-else>未入库</span>
              </template>
            </el-table-column>
            <el-table-column prop="order.sendTypeName" label="配送方式" width="120">
            </el-table-column>
            <el-table-column show-overflow-tooltip prop="order.sendTime" label="要求到达时间" width="140">
            </el-table-column>
            <el-table-column prop="order.agingName" label="运输方式" width="120">
            </el-table-column>
            <el-table-column prop="order.orderPrice" label="运费(元)" width="90">
              <template slot-scope="scope">
                <span v-if="scope.row.pid===null">{{scope.row.order.orderPrice}}</span>
              </template>
            </el-table-column>
            <el-table-column prop="order.paymentTypeName" label="结算方式" width="100">
            </el-table-column>
            <el-table-column prop="order.shipmentsContactName" label="发货人名称" width="160">
            </el-table-column>
            <el-table-column prop="order.remark" label="备注" width="120">
            </el-table-column>
            <el-table-column fixed="right" prop="order" label="件重体" width="140" :formatter="formatterOrderCargos">
            </el-table-column>
          </ue-el-table>
        </el-tab-pane>
      </el-tabs>
    </div>
   </section>
</template>

<script>
import {
  trunkTasksPageSub,
  goodsVehicleStatistics,
  sendRegionAndNum,
  shipmentsRegionAndNum,
  splitTrunkTask,
  cancleSplitTrunkTask,
  isCancleSplitTrunkTask
} from '../../api/stowage/TrunkTask';
import { getOrganizationById } from '../../api/organization/Organization';
import {
  searchAllVehicleInfo,
  saveVehicleInfoTemporary,
  searchVehicleInfoTemporary
} from '../../api/stowage/VehicleManage';
import { addLoadingList, pageLoadingList } from '../../api/stowage/LoadingList';
import { batchAddLoadingListTrunkTask, deleteLoadingListTrunkTask, direct } from '../../api/stowage/LoadingListTrunkTask';
import SplitTask from './split-task/SplitTask.vue';
export default{
  components: {
    SplitTask
  },
  data () {
    return {
      ageingDisplay: {
        display: 'none'
      },
      isCancleSplitTrunkTask: false,
      selectedNoStowageTrunkTask: null,
      tabActiveName: 'first',
      currentOrganizationIds: [],
      selectedLoadingList: null,
      code: '',
      tableData: [],
      left: {
        addVehicleDialogVisible: false,
        vehicleForm: {
          plateNumber: null,
          name: null,
          phone: null
        },
        goodsVehicleStatistics: {
          ageingWarningNum: 0,
          vehicleNum: 0,
          orderStatistics: {
            orderSum: 0,
            total: 0,
            totalVolume: 0,
            totalWeight: 0
          }
        },
        id: null,
        vehicles: [],
        vehicleTableDataTemporary: [],
        searchVehicleLoading: false,
        endOrganizationInput: false,
        loadingListRoute: {
          vehicle: null,
          startOrganizationId: [],
          site: [{
            organizationId: []
          }],
          endOrganizationId: [],
          endOrganizationName: null
        },
        loadingList: {
          tableData: [],
          total: 0,
          currentPage: 1,
          pageSize: 10,
          listLoading: false
        }
      },
      center: {
        haveStowage: {
          orderType: false,
          loadingListRouteId: null,
          routes: [],
          loadingListId: null,
          tableData: [],
          listLoading: false,
          sels: [],
          totalAmount: 0,
          totalWeight: 0,
          totalVolume: 0,
          totalPoll: 0,
          searchCondition: {}
        },
        noStowage: {
          orderType: false,
          loadingListRouteId: null,
          routes: [],
          sels: [],
          totalAmount: 0,
          totalWeight: 0,
          totalVolume: 0,
          totalPoll: 0,
          tableData: [],
          listLoading: false,
          searchCondition: {}
        }
      }
    };
  },
  computed: {
    btns () {
      return this.$store.state.btns[this.$route.path] || [];
    },
    querysNoStowage () {
      return this.$store.state.querys[this.$route.path + '#no_stowage'] || [];
    },
    querysHaveStowage () {
      return this.$store.state.querys[this.$route.path + '#have_stowage'] || [];
    }
  },
  watch: {
    tabActiveName (val) {
      if (val === 'first') {
        this.noStowageSearch('');
      } else {
        this.haveStowageQuery();
      }
    },
    'center.noStowage.sels': {
      handler (sels) {
        let ids = sels.filter(item => (item.type === 'group' || item.childrenNum > 0)).map(i => i.id);
        let totalAmount = 0;
        let totalWeight = 0;
        let totalVolume = 0;
        let totalPoll = 0;
        sels.forEach(item => {
          if (item.type === 'group') {
            totalAmount += item.amount;
            totalWeight += item.weight;
            totalVolume += item.volume;
            totalPoll += item.num;
          } else {
            if (ids.indexOf(item.parent_id) === -1 && ids.indexOf(item.pid) === -1) {
              totalAmount += item.amount;
              totalWeight += item.weight;
              totalVolume += item.volume;
              totalPoll += (item.childNodeNum || 1);
            }
          }
        });
        this.center.noStowage.totalAmount = totalAmount;
        this.center.noStowage.totalWeight = totalWeight;
        this.center.noStowage.totalVolume = totalVolume;
        this.center.noStowage.totalPoll = totalPoll;
      },
      deep: true
    },
    'center.haveStowage.sels': {
      handler (sels) {
        let ids = sels.filter(item => item.type === 'group' || item.childrenNum > 0).map(i => i.id);
        let totalAmount = 0;
        let totalWeight = 0;
        let totalVolume = 0;
        let totalPoll = 0;
        sels.forEach(item => {
          if (item.type === 'group') {
            totalAmount += item.amount;
            totalWeight += item.weight;
            totalVolume += item.volume;
            totalPoll += item.num;
          } else {
            let v = item;
            if (ids.indexOf(item.parent_id) === -1 && v) {
              totalAmount += v.amount;
              totalWeight += v.weight;
              totalVolume += v.volume;
              totalPoll += (item.childNodeNum || 1);
            }
          }
        });
        this.center.haveStowage.totalAmount = totalAmount;
        this.center.haveStowage.totalWeight = totalWeight;
        this.center.haveStowage.totalVolume = totalVolume;
        this.center.haveStowage.totalPoll = totalPoll;
      },
      deep: true
    },
    'center.noStowage.orderType': {
      handler (val) {
        this.noStowageSearch(this.$ue.objToFilter(this.center.noStowage.searchCondition));
      },
      deep: true
    },
    'center.haveStowage.orderType': {
      handler () {
        this.haveStowageQuery(this.$ue.objToFilter(this.center.haveStowage.searchCondition));
      },
      deep: true
    }
  },
  methods: {
    tableRowClassName (row, index) {
      let cssName = '';
      if (row.childrenNum > 0) {
        cssName += 'split_order';
      };
      if (row.order && (row.order.noticeDeliveryStatus === 101022002 || row.order.noticeDeliveryStatus === 101022003)) {
        cssName += ' row-info-bg';
      };
      if (row && row.ageingWarning) {
        cssName += ' split-order-ageing';
      }
      return cssName;
    },
    handleNoStowageCurrentChange (val) {
      this.selectedNoStowageTrunkTask = val;
      if (val && val.childrenNum !== null) {
        isCancleSplitTrunkTask(val.id).then(res => {
          if (res.data.successFlg) {
            this.isCancleSplitTrunkTask = res.data.obj;
          }
        });
      } else {
        this.isCancleSplitTrunkTask = false;
      }
    },
    confirmSplitHandle (data) {
      splitTrunkTask(this.selectedNoStowageTrunkTask.id, data)
        .then(res => {
          if (res.data.successFlg) {
            this.noStowageQuery();
            this.$message('拆单成功');
          } else {
            this.$message.error(res.data.errorMsg);
          }
        });
    },
    removeSplit () {
      this.$confirm('您确认取消该订单的拆单?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        cancleSplitTrunkTask(this.selectedNoStowageTrunkTask.id)
          .then(res => {
            if (res.data.successFlg) {
              this.$message('取消拆单成功');
              this.noStowageQuery();
            } else {
              this.$message.error(res.data.errorMsg);
            }
          });
      }).catch(() => {
      });
    },
    confirmSplit () {
      this.$refs.mySplitTask.show();
    },
    noStowageExport () {
      // todo
    },
    noStowageSelect (sel, row) {
      this.parentSelect('noStowageTable', sel, row);
    },
    haveStowageSelect (sel, row) {
      this.parentSelect('haveStowageTable', sel, row);
    },
    parentSelect (ref, sel, row) {
      let self = this;
      let ids = sel.map(i => i.id);
      const traverseCheckedChilNodes = function (node) {
        const childNodes = node.children;
        if (childNodes) {
          childNodes.forEach((child) => {
            if (ids.indexOf(child.id) === -1) {
              self.$refs[ref].toggleRowSelection(child);
            }
            traverseCheckedChilNodes(child);
          });
        }
      };
      const traverseUnCheckChilNodes = function (node) {
        const childNodes = node.children;
        if (childNodes) {
          childNodes.forEach((child) => {
            if (ids.indexOf(child.id) > -1) {
              self.$refs[ref].toggleRowSelection(child, false);
            }
            traverseUnCheckChilNodes(child);
          });
        }
      };

      const traverseParent = function (node, checked = true) {
        let id = node.$pid;
        while (id) {
          if (checked) {
            let children = sel.filter(item => {
              return item.$pid === id;
            });
            let parents = self.$refs[ref].store.states.data.filter(item => {
              return item.id === id;
            });
            if (parents.length > 0 && parents[0].children.length === children.length) {
              self.$refs[ref].toggleRowSelection(parents[0]);
              id = parents[0].$pid;
            } else {
              id = null;
            }
          } else {
            let parents = sel.filter(item => {
              return item.id === id;
            });
            if (parents.length > 0) {
              self.$refs[ref].toggleRowSelection(parents[0], false);
              id = parents[0].$pid;
            } else {
              id = null;
            }
          }
        }
      };
      if (sel.indexOf(row) > -1) {
        if (row.children) {
          traverseCheckedChilNodes(row);
        } else {
          traverseParent(row, true);
        }
      } else {
        if (row.children) {
          traverseUnCheckChilNodes(row);
        } else {
          traverseParent(row, false);
        }
      }
    },

    // 加载历史临时车辆
    loadVehicleTemporary () {
      let filters = 'EQ_usage=109010003';
      searchVehicleInfoTemporary({
        filters: filters,
        size: 6,
        page: 1
      }).then(res => {
        if (res.data.successFlg === true) {
          this.left.vehicleTableDataTemporary = res.data.detailModelList;
        }
      });
    },
    // 选择历史使用临时车辆
    selectVehicleInfoTemporary (item) {
      this.left.vehicleForm.plateNumber = item.plateNumber;
      this.left.vehicleForm.name = item.contactPerson;
      this.left.vehicleForm.phone = item.contactPhone;
    },
    // 新增临时车辆按钮
    addVehicle () {
      if (this.$refs.addVehicleForm) {
        this.$refs.addVehicleForm.resetFields();
      }
      this.left.addVehicleDialogVisible = true;
      this.loadVehicleTemporary();
    },
    // 新增临时车辆（保存数据库）
    saveVehicle () {
      this.$refs.addVehicleForm.validate((valid) => {
        if (valid) {
          let item = {
            id: null,
            plateNumber: this.left.vehicleForm.plateNumber,
            driverInfos: [{
              id: null,
              name: this.left.vehicleForm.name,
              phone: this.left.vehicleForm.phone
            }]
          };
          if (this.left.loadingListRoute.vehicle == null || this.left.loadingListRoute.vehicle.plateNumber !== item.plateNumber) {
            this.left.vehicles.push(item);
            this.left.loadingListRoute.vehicle = item;
            // 保存临时车辆信息
            let vehicleInfoTemporary = {
              plateNumber: this.left.vehicleForm.plateNumber,
              contactPerson: this.left.vehicleForm.name,
              contactPhone: this.left.vehicleForm.phone,
              usage: 109010003
            };
            saveVehicleInfoTemporary(vehicleInfoTemporary).then((res) => {});
          }
          this.left.addVehicleDialogVisible = false;
        }
      });
    },
    haveStowageLoadingListRouteChange (val) {
      this.center.haveStowage.searchCondition['EQ_loadingListTrunkTask.loadingListRoute.id'] = val;
      this.haveStowageQuery();
    },
    formatterOrderCargos (row) {
      return row.amount + '件/' + row.weight.toFixed(2) + '吨/' + row.volume.toFixed(2) + '方';
    },
    removeLoadingListTunkTask () {
      this.$confirm('您确认移出该装车单?', '提示', {
        type: 'warning'
      }).then(() => {
        let ids = this.center.haveStowage.sels.map(item => {
          return {
            id: item.type === 'group' ? item.id : (item.childrenNum ? item.id : item.loadingListTrunkTask.id),
            type: item.type === 'group' ? (this.center.haveStowage.orderType ? 'shipments_group' : 'send_group') : (item.childrenNum ? 'parent' : '')
          };
        });
        let o = {};
        Object.keys(this.center.haveStowage.searchCondition).forEach(k => {
          let ks = k.split('_');
          o[ks[0] + '_trunkTask.' + ks[1]] = this.center.haveStowage.searchCondition[k];
        });
        deleteLoadingListTrunkTask(this.$ue.objToFilter(o) + ';', this.selectedLoadingList.id, ids).then(res => {
          if (res.data.successFlg) {
            this.$message({
              message: '移出成功',
              type: 'success'
            });
            this.haveStowageQuery();
            this.noStowageQuery();
            this.selectedLoadingList.poll -= this.center.haveStowage.totalPoll;
            this.selectedLoadingList.totalWeight -= this.center.haveStowage.totalWeight;
            this.selectedLoadingList.totalVolume -= this.center.haveStowage.totalVolume;
            this.selectedLoadingList.totalAmount -= this.center.haveStowage.totalAmount;
          } else {
            this.$message.error(res.data.errorMsg);
          }
        });
      });
    },
    handleDirect () {
      this.$confirm('已选订单确定需要大车直送到收货人地址吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let params = [];
        this.center.noStowage.sels.forEach(item => {
          params.push({
            id: item.id,
            type: item.type === 'group' ? (this.center.noStowage.orderType ? 'shipments_group' : 'send_group') : (item.childrenNum ? 'parent' : '')
          });
        });
        let o = {};
        Object.keys(this.center.noStowage.searchCondition).forEach(k => {
          let ks = k.split('_');
          const split = (ks[1] || '').split('.');
          let vs = split.map((currentValue, index, array) => {
            if (index === split.length - 1) {
              return currentValue;
            } else {
              return 'LEFT_' + currentValue;
            }
          }).join('.');
          o[ks[0] + '_' + vs] = this.center.noStowage.searchCondition[k];
        });
        direct(this.$ue.objToFilter(o) + ';', this.selectedLoadingList.id, params)
          .then(res => {
            if (res.data.successFlg) {
              this.$message.success('大车直送设置成功!');
              this.loadingLists('');
              this.noStowageQuery();
              this.haveStowageQuery();
            }
          });
      }).catch(() => {});
    },
    addLoadingListTunkTask () {
      if (this.center.noStowage.loadingListRouteId === null) {
        this.$message.warning('请选择下货地');
        return;
      }
      let o = {};
      Object.keys(this.center.noStowage.searchCondition).forEach(k => {
        let ks = k.split('_');
        const split = (ks[1] || '').split('.');
        let vs = split.map((currentValue, index, array) => {
          if (index === split.length - 1) {
            return currentValue;
          } else {
            return 'LEFT_' + currentValue;
          }
        }).join('.');
        o[ks[0] + '_' + vs] = this.center.noStowage.searchCondition[k];
      });
      let params = [];
      this.center.noStowage.sels.forEach(item => {
        params.push({
          id: item.id,
          type: item.type === 'group' ? (this.center.noStowage.orderType ? 'shipments_group' : 'send_group') : (item.childrenNum ? 'parent' : '')
        });
      });
      batchAddLoadingListTrunkTask(this.$ue.objToFilter(o) + ';', this.center.noStowage.loadingListRouteId, params)
        .then(res => {
          if (res.data.successFlg) {
            this.$message.success('移入成功!');
            this.noStowageQuery();
            this.haveStowageQuery();
            this.selectedLoadingList.poll += this.center.noStowage.totalPoll;
            this.selectedLoadingList.totalWeight += this.center.noStowage.totalWeight;
            this.selectedLoadingList.totalVolume += this.center.noStowage.totalVolume;
            this.selectedLoadingList.totalAmount += this.center.noStowage.totalAmount;
          }
        });
    },
    deleteLoadingListRoute (index, item) {
      this.$confirm('您确认删除该途径站?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        delete this.left.loadingListRoute.site.splice(index, 1);
      });
    },
    labels (values) {
      let options = this.$store.state.initOrganizations;
      let labels = [];
      values.forEach(value => {
        const targetOption = options && options.filter(option => option.id === value)[0];
        if (targetOption) {
          labels.push(targetOption.name);
          options = targetOption.children;
        }
      });
      return labels;
    },
    currentLabels (values) {
      return this.labels(values).join('/');
    },
    loadingListHandleCurrentChange (val) {
      if (val) {
        this.selectedLoadingList = val;
        this.code = val.number;
        this.left.id = val.id;
        let item = {
          id: val.vehicleInfoId,
          plateNumber: val.plateNumber,
          driverInfos: [{
            id: val.driverInfoId,
            name: val.driverInfoName,
            phone: val.driverInfoPhone
          }]
        };
        if (this.left.loadingListRoute.vehicle == null || this.left.loadingListRoute.vehicle.plateNumber !== item.plateNumber) {
          this.left.loadingListRoute.vehicle = item;
        }
        this.left.loadingListRoute.site = [];
        const ts = val.routes.filter(o => o.isDirect === false);
        this.center.noStowage.routes = Object.assign([], ts);
        this.center.noStowage.routes.splice(0, 1);
        this.center.noStowage.loadingListRouteId = null;
        this.center.noStowage.dischargeOrganizationId = null;
        this.center.haveStowage.routes = val.routes;
        this.center.haveStowage.loadingListRouteId = null;
        this.center.haveStowage.loadingListId = val.id;
        for (let i = 0; i < ts.length; i++) {
          let route = ts[i];
          let organizationIds = [];
          if (route.dischargeOrganizationIds) {
            organizationIds = route.dischargeOrganizationIds.split(',');
          }
          if (i === 0) {
            this.left.loadingListRoute.startOrganizationId = organizationIds;
          } else if (i === (ts.length - 1)) {
            this.left.loadingListRoute.endOrganizationId = organizationIds;
            if (organizationIds.length === 0) {
              this.left.endOrganizationInput = true;
              this.left.loadingListRoute.endOrganizationName = route.dischargeOrganizationName;
            }
          } else {
            this.left.loadingListRoute.site.push({organizationId: organizationIds, id: route.id});
          }
        }
        this.haveStowageSearch();
      } else {
        this.selectedLoadingList = null;
        this.center.haveStowage.loadingListId = null;
        this.center.haveStowage.tableData = [];
        this.resetLoadingList();
      }
    },
    lastCurrentLabels (values) {
      let arrs = this.labels(values);
      if (arrs.length) {
        return arrs[arrs.length - 1];
      } else {
        return '';
      }
    },
    resetLoadingList () {
      this.$refs['loadingListForm'].resetFields();
      this.left.loadingListRoute.site = [{
        organizationId: []
      }];
      this.code = '';
      this.left.id = null;
      this.center.noStowage.loadingListRouteId = null;
      this.center.noStowage.routes = [];
      this.center.noStowage.dischargeOrganizationId = null;
      this.center.haveStowage.loadingListRouteId = null;
      this.center.haveStowage.routes = [];
      this.left.loadingListRoute.vehicle = null;
      this.left.loadingListRoute.startOrganizationId = Object.assign([], this.currentOrganizationIds);
      this.$refs.singleTable.setCurrentRow();
    },
    addLoadingList () {
      this.$refs['loadingListForm'].validate((valid) => {
        if (valid) {
          let vehicle = this.left.loadingListRoute.vehicle;
          if (vehicle.driverInfos.length) {
            let driver = vehicle.driverInfos[0];
            let o = {
              'id': this.left.id,
              'routes': [],
              'vehicleInfoId': vehicle.id,
              'plateNumber': vehicle.plateNumber,
              'driverInfoId': driver.id,
              'driverInfoName': driver.name,
              'driverInfoPhone': driver.phone
            };
            let startOrganization = this.currentOrganizationIds;
            o.routes.push({
              dischargeOrganizationIds: startOrganization.join(','),
              dischargeOrganizationId: startOrganization[startOrganization.length - 1],
              dischargeOrganizationName: this.lastCurrentLabels(startOrganization)
            });
            this.left.loadingListRoute.site.forEach(item => {
              let organizationIds = item.organizationId;
              if (organizationIds.length) {
                o.routes.push({
                  dischargeOrganizationIds: organizationIds.join(','),
                  dischargeOrganizationId: organizationIds[organizationIds.length - 1],
                  dischargeOrganizationName: this.lastCurrentLabels(organizationIds)
                });
              }
            });
            if (this.left.endOrganizationInput) {
              o.routes.push({
                dischargeOrganizationIds: null,
                dischargeOrganizationId: null,
                dischargeOrganizationName: this.left.loadingListRoute.endOrganizationName
              });
            } else {
              let endOrganization = this.left.loadingListRoute.endOrganizationId;
              o.routes.push({
                dischargeOrganizationIds: endOrganization.join(','),
                dischargeOrganizationId: endOrganization[endOrganization.length - 1],
                dischargeOrganizationName: this.lastCurrentLabels(endOrganization)
              });
            }
            addLoadingList(o).then(res => {
              if (res.data.successFlg) {
                this.loadingLists('');
                this.resetLoadingList();
              } else {
                this.$message.error(res.data.errorMsg);
              }
            });
          } else {
            this.$message.warning('该车辆还未分配司机，请选择另一辆');
          }
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    addLoadingListRoute () {
      this.left.loadingListRoute.site.push({
        organizationId: [],
        key: Date.now()
      });
    },
    searchVehicle () {
      this.left.searchVehicleLoading = true;
      let filters = 'IN_usage=109010001,109010003;';
      searchAllVehicleInfo({
        filters: filters,
        sorts: ''
      }).then(res => {
        if (res.data.successFlg) {
          this.left.searchVehicleLoading = false;
          this.left.vehicles = res.data.detailModelList;
        }
      });
    },
    noStowageSelsChange (sels) {
      this.center.noStowage.sels = sels;
    },
    haveStowageSelsChange (sels) {
      this.center.haveStowage.sels = sels;
    },
    trunkTasks (filter, orFilters, sorts, success) {
      trunkTasksPageSub({
        filters: filter,
        orFilters: orFilters,
        sorts: sorts
      }).then(res => {
        if (res.data.successFlg) {
          success(res.data);
        }
      });
    },
    loadingListSizeChange (val) {
      this.left.loadingList.pageSize = val;
      this.loadingLists('');
    },
    loadingListCurrentChange (val) {
      this.left.loadingList.currentPage = val;
      this.loadingLists('');
    },
    loadingLists (filter) {
      this.left.loadingList.listLoading = true;
      pageLoadingList({
        filters: 'EQ_status=105007001;' + filter,
        size: this.left.loadingList.pageSize,
        page: this.left.loadingList.currentPage
      }).then(res => {
        if (res.data.successFlg) {
          this.left.loadingList.tableData = res.data.detailModelList;
          this.left.loadingList.currentPage = res.data.currPage;
          this.left.loadingList.total = res.data.totalCount;
          this.left.loadingList.pageSize = res.data.pageSize;
          this.left.loadingList.listLoading = false;
        }
      });
    },
    remoteNoStowage (row, callback) {
      let filters = 'ISNULL_LEFT_loadingListTrunkTask.id;' + this.$ue.objToFilter(this.center.noStowage.searchCondition) + ';';
      let orFilters;
      let depth = 0;
      if (row.type === 'group') {
        let o = {};
        Object.keys(this.center.noStowage.searchCondition).forEach(k => {
          let ks = k.split('_');
          const split = (ks[1] || '').split('.');
          let vs = split.map((currentValue, index, array) => {
            if (index === split.length - 1) {
              return currentValue;
            } else {
              return 'LEFT_' + currentValue;
            }
          }).join('.');
          o[ks[0] + '_LEFT_children.' + vs] = this.center.noStowage.searchCondition[k];
        });
        orFilters = ';ISNULL_LEFT_children.LEFT_loadingListTrunkTask.id;' + this.$ue.objToFilter(o) + ';';
        filters += ';ISNULL_childrenNum;ISNULL_parent;';
        if (!this.center.noStowage.orderType) {
          filters += ';EQ_sendCountyId=' + row.id + ';';
          orFilters += ';EQ_LEFT_children.sendCountyId=' + row.id + ';';
        } else {
          filters += ';EQ_shipmentsCountyId=' + row.id + ';';
          orFilters += ';EQ_LEFT_children.shipmentsCountyId=' + row.id + ';';
        }
        depth = 1;
      } else {
        filters += 'EQ_parent.id=' + row.id;
        if (!this.center.noStowage.orderType) {
          filters += ';EQ_sendCountyId=' + row.parent_id + ';';
        } else {
          filters += ';EQ_shipmentsCountyId=' + row.parent_id + ';';
        }
        depth = 2;
      }
      this.trunkTasks(
        filters,
        orFilters,
        '-shipmentsDate',
        data => {
          let items = data.detailModelList;
          items.forEach(item => {
            item.parent_id = row.id;
            item.depth = depth;
            if (item.childrenNum) {
              item.num = item.childrenNum;
              item.label += ('(拆-' + item.childrenNum + ')');
            }
          });
          callback(items);
        }
      );
    },
    noStowageSearch (filters) {
      this.center.noStowage.listLoading = true;
      if (this.center.noStowage.orderType) {
        this.loadShipmentsRegionAndNum('ISNULL_childrenNum;ISNULL_LEFT_loadingListTrunkTask.id;' + filters, data => {
          this.center.noStowage.listLoading = false;
          this.center.noStowage.tableData = data;
        });
      } else {
        this.loadSendRegionAndNum('ISNULL_childrenNum;ISNULL_LEFT_loadingListTrunkTask.id;' + filters, data => {
          this.center.noStowage.listLoading = false;
          this.center.noStowage.tableData = data;
        });
      }
    },
    remoteHaveStowage (row, callback) {
      let filters = 'EQ_LEFT_loadingListTrunkTask.LEFT_loadingListRoute.LEFT_loadingList.id=' + this.center.haveStowage.loadingListId + ';' + this.$ue.objToFilter(this.center.haveStowage.searchCondition) + ';';
      let orFilters;
      let depth = 0;
      if (row.type === 'group') {
        let o = {};
        Object.keys(this.center.haveStowage.searchCondition).forEach(k => {
          let ks = k.split('_');
          o[ks[0] + '_LEFT_children.' + ks[1]] = this.center.noStowage.searchCondition[k];
        });
        orFilters = 'EQ_LEFT_children.LEFT_loadingListTrunkTask.LEFT_loadingListRoute.LEFT_loadingList.id=' + this.center.haveStowage.loadingListId + ';' + this.$ue.objToFilter(o) + ';';
        filters += ';ISNULL_childrenNum;ISNULL_parent;';
        if (!this.center.haveStowage.orderType) {
          filters += ';EQ_sendCountyId=' + row.id + ';';
          orFilters += ';EQ_LEFT_children.sendCountyId=' + row.id + ';';
        } else {
          filters += ';EQ_shipmentsCountyId=' + row.id + ';';
          orFilters += ';EQ_LEFT_children.shipmentsCountyId=' + row.id + ';';
        }
        depth = 1;
      } else {
        filters += 'EQ_parent.id=' + row.id;
        if (!this.center.haveStowage.orderType) {
          filters += ';EQ_sendCountyId=' + row.parent_id + ';';
        } else {
          filters += ';EQ_shipmentsCountyId=' + row.parent_id + ';';
        }
        depth = 2;
      }
      this.trunkTasks(
        filters,
        orFilters,
        '-shipmentsDate',
        data => {
          let items = data.detailModelList;
          items.forEach(item => {
            item.parent_id = row.id;
            item.depth = depth;
            if (item.childrenNum) {
              item.num = item.childrenNum;
              item.label += ('(拆-' + item.childrenNum + ')');
            }
          });
          callback(items);
        }
      );
    },
    haveStowageQuery () {
      this.haveStowageSearch(this.$ue.objToFilter(this.center.haveStowage.searchCondition));
    },
    haveStowageSearch (filters = '') {
      this.center.haveStowage.listLoading = true;
      filters += ';ISNULL_childrenNum;EQ_loadingListTrunkTask.loadingListRoute.loadingList.id=' + this.center.haveStowage.loadingListId + ';';
      if (this.center.haveStowage.orderType) {
        this.loadShipmentsRegionAndNum(filters, data => {
          this.center.haveStowage.listLoading = false;
          this.center.haveStowage.tableData = data;
        });
      } else {
        this.loadSendRegionAndNum(filters, data => {
          this.center.haveStowage.listLoading = false;
          this.center.haveStowage.tableData = data;
        });
      }
    },
    haveStowageReset () {
      this.$refs.ueSearchBarHaveStowage.reset();
    },
    noStowageQuery () {
      this.noStowageSearch(this.$ue.objToFilter(this.center.noStowage.searchCondition));
    },
    noStowageReset () {
      this.$refs.ueSearchBarNoStowage.reset();
    },
    loadSendRegionAndNum (filters, fn) {
      sendRegionAndNum({
        filters: filters
      }).then(res => {
        if (res.data.successFlg === true) {
          fn(res.data.detailModelList.map(item => {
            item.type = 'group';
            item.depth = 0;
            return item;
          }));
        }
      });
    },
    loadShipmentsRegionAndNum (filters, fn) {
      shipmentsRegionAndNum({
        filters: filters
      }).then(res => {
        if (res.data.successFlg === true) {
          fn(res.data.detailModelList.map(item => {
            item.type = 'group';
            item.depth = 0;
            return item;
          }));
        }
      });
    }
  },
  mounted () {
    goodsVehicleStatistics()
      .then(res => {
        if (res.data.successFlg) {
          this.left.goodsVehicleStatistics = res.data.obj;
          if (this.left.goodsVehicleStatistics.ageingWarningNum === 0) {
            this.ageingDisplay.display = 'none';
          } else {
            this.ageingDisplay.display = 'block';
          }
        }
      });
    getOrganizationById(this.$store.state.currentOrganizationId).then(res => {
      if (res.data.successFlg) {
        if (res.data.obj) {
          let ids = Object.assign([], res.data.obj.pids);
          ids.push(res.data.obj.id);
          this.currentOrganizationIds = Object.assign([], ids);
          this.left.loadingListRoute.startOrganizationId = Object.assign([], ids);
        } else {
          this.currentOrganizationIds = [];
          this.left.loadingListRoute.startOrganizationId = [];
        }
      }
    });
    this.noStowageSearch('');
    this.loadingLists('');
    this.$store.commit('initOrganizations');
    this.$store.commit('initDict');
    this.searchVehicle();
  }
};
</script>
